#ifndef _EK_ENV_H_
#define _EK_ENV_H_

/*

  Time-stamp: <2009-11-14 14:54:24 xinhaoyuan>

  File: env.c env.h

  This file contains routines manage environments. The scheduling
  granularity unit in the system.

  The environment structures are stored in a pre-allocated env array.
  
    - int env_idx_alloc() -- allocate a new env array element, return the idx
	- void env_idx_free(uint16_t idx)  -- deallocate a env array element
	
	- void fork(struct trapframe_t *tf) -- classical fork
	- void sfork(struct trapframe_t *tf) -- fork a new thread belong to the same process
	
*/

/* envs array */
extern struct env_t *envs;

extern uint32_t env_id_count;

extern int env_free_head;
extern int env_sfree_head;

/* the lock of allocation */
extern uint8_t envs_alloc_lock;

int env_idx_alloc(void);
void env_idx_sfree(uint16_t idx);

void fork(struct trapframe_t *tf);
void sfork(struct trapframe_t *tf);


#endif /* _EK_ENV_H_ */
